<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>Bootstrap 实例 - 水平表单</title>
  <link rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/css/bootstrap.min.css">
  <script src="https://cdn.staticfile.org/jquery/2.1.1/jquery.min.js"></script>
  <script src="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<body>

<form class="form-horizontal" role="form">
  <div class="form-group">
    <div class="col-sm-10">
      <input type="text" class="form-control" id="oldPassword"
             placeholder="请输入原密码">
    </div>
  </div>
  <div class="form-group">
    <div class="col-sm-10">
      <input type="text" class="form-control" id="newPassword"
             placeholder="请输入新密码">
    </div>
  </div>
  <div class="form-group">
    <div class="col-sm-10">
      <input type="text" class="form-control" id="resNewPassword"
             placeholder="请再次输入新密码">
    </div>
  </div>
  <div class="form-group">
    <div class="col-sm-offset-2 col-sm-10">
      <button type="button" class="btn btn-default" id="changePwd">修改</button>
    </div>
  </div>
</form>

</body>
</html>

<script>
  $(function (){
    $('#oldPassword').blur(function (){
      if($(this).val()==''){
        alert('原密码不能为空')
      }
    })
    $('#newPassword').blur(function (){
      if($('#newPassword').val()==''){
        alert('新密码不能为空')
      }
    })
    $('#resNewPassword').blur(function (){
      if($('#resNewPassword').val()==''){
        alert('再次输入的密码不能为空')
      }else {
        if($('#resNewPassword').val()!=$('#newPassword').val()){
          alert('两次输入的密码不一致，请重新输入')
        }
      }
    })
    $('#changePwd').click(function (){
      var oldPassword=$('#oldPassword').val();
      var newPassword=$('#newPassword').val();
      var resNewPassword=$('#resNewPassword').val();
      $.ajax({
        url:"{:url('/changePwd')}",
        data:{oldPassword:oldPassword,newPassword:newPassword,resNewPassword:resNewPassword},
        type:'post',
        dataType:'json',
        success:function (e){
          if(e.code==200){
            location.href='login'
          }else {
            alert(e.msg);
          }
        }
      })
    })

  })
</script>